#ifndef _PROTO_HELPER_H_
#define _PROTO_HELPER_H_

#include <json/json.h>
#include <string>

#include "SocketConnPtr.h"

#define OK_RESULT 0

using std::string;

int recv_cmd(int fd, const int recv_timeout, const int max_cmd_size, string & buf);

int recv_cmd(SocketConnPtr & conn, const int recv_timeout, const int max_cmd_size, string & buf);

int send_cmd(SocketConnPtr & conn, const int send_timeout, const void * buf, const int len);

int send_cmd(int fd, const int send_timeout, const void * buf, const int len);

int send_and_recv_cmd(SocketConnPtr & conn, const int send_timeout, const int recv_timeout, const void * send_buf, \
			const int send_len, const int max_recv_packet_size, string & recv_buf);

int parse_request(const char * request, const int len, json_object * & j, int & cmd_id);

int recv_and_parse_request(int fd,  int socket_recv_timeout, int max_request_size, json_object * & j, int & cmd_id, \
			string & request);

string build_error_response(int result, const char * err_msg = "");

string build_ok_response(const char * tips = "");

#endif
